﻿using TCC.Framework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TCC.Framework
{
    public class FSMSystem:IReference
    {
        private GameObject _fsmEntity;

        /// <summary>
        /// 状态机实体
        /// </summary>
        public GameObject FsmEntity
        {
            get => _fsmEntity;
            private set { }
        }

        private FSMDataBase _currentStateData;

        /// <summary>
        /// 当前状态机使用数据
        /// </summary>
        public FSMDataBase CurrentStateData
        {
            get => _currentStateData;
            private set => _currentStateData = _currentState.m_fsmData;
        }

        private StateBase _currentState;
        /// <summary>
        /// 当前状态
        /// </summary>
        public StateBase CurrentState
        {
            get => _currentState;
            private set { }
        }

        private StateBase _defaultState;

        /// <summary>
        /// 默认状态
        /// </summary>
        public StateBase DefaultState
        {
            get => _defaultState;
            private set { }
        }

        public FSMSystem(GameObject fsmEntity,StateBase defaultState)
        {
            FsmEntity = fsmEntity;
            DefaultState = defaultState;
            CurrentStateData = DefaultState.m_fsmData;
        }


        public void UpdateState()
        {

        }

        /// <summary>
        /// 切换状态
        /// </summary>
        public void SwitchState(StateBase nextState)
        {
            CurrentState.OnExitState();
            CurrentState = nextState;
            CurrentState.OnEnterState();
        }

        public void Reset()
        {
            FsmEntity = null;
            CurrentStateData = null;
            CurrentState = null;
            DefaultState = null;
        }
    }
}